package cn.com.taurus.controller.datatable;

import cn.com.taurus.bean.RedeemMessageBean;
import cn.com.taurus.biz.AdminLogBiz;
import cn.com.taurus.biz.DealMessageBiz;
import cn.com.taurus.biz.RedeemMessageBiz;
import cn.com.taurus.entity.AdminLog;
import cn.com.taurus.entity.DealMessage;
import cn.com.taurus.entity.RedeemMessage;
import cn.com.taurus.util.Log;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * @author zjw
 * @createTime 2021年6月28日
 * @remark 基金公司控制层
 * @version 1.0
 */
@Controller
public class RedeemMessageController {
    @Autowired
    RedeemMessageBiz redeemMessageBiz;

    @RequestMapping("/redeemMessage")
    public String redeemMessage() {
        return "datatable/redeemMessage";
    }

    @RequestMapping("/updateRedeemMessage")
    @Log(operation = "修改赎回申请信息",type = 2)
    public String updateRedeemMessage(@ModelAttribute RedeemMessage redeemMessage){
        redeemMessageBiz.redeemApplicationUpdate(redeemMessage);
        return "datatable/redeemMessage";
    }

    @RequestMapping("/deleteRedeemMessage")
    @Log(operation = "删除赎回申请信息",type = 3)
    public String deleteRedeemMessage(Integer rmId){
        redeemMessageBiz.redeemApplicationDelete(rmId);
        return "datatable/redeemMessage";
    }

    /**
     * 模糊查询
     * @param pageNum 几条
     * @param pageSize 数量
     * @param caId 客户账户编号
     * @param fId 基金编号
     * @param applyRedeem 申请赎回金额
     * @param applyTime 开始时间
     * @param time 结束时间
     * @return
     */
    @ResponseBody
    @RequestMapping("/conditionSelectRedeemMessage")
    @Log(operation = "条件查询赎回申请信息",type = 1)
    public HashMap conditionSelectRedeemMessage(Integer pageNum, Integer pageSize, String caId, String fId, String applyRedeem,String applyTime,String time){
        System.out.println(applyTime);
        System.out.println(time);
        HashMap<String, Object> map = new HashMap<>();
        //开启分页支持
        PageHelper.startPage(pageNum,pageSize);
        List<RedeemMessageBean> rule = redeemMessageBiz.conditionSelectRedeemMessage(caId,fId,applyRedeem,applyTime,time);;
        PageInfo<RedeemMessageBean> pageInfo = new PageInfo<>(rule);
        System.out.println("数据："+pageInfo.getPages());
        map.put("code",0);
        map.put("msg","请求成功");
        //count：总数据条数
        map.put("count",pageInfo.getTotal());
        //data：数据
        map.put("data",pageInfo.getList());
        return map;
    }

    /**
     * 分页
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping("/selectRedeemMessage")
    public HashMap selectRedeemMessage(Integer pageNum,Integer pageSize){
        HashMap<String, Object> map = new HashMap<>();
        // 开启分页支持
        PageHelper.startPage(pageNum,pageSize);
        List<RedeemMessage> rule = redeemMessageBiz.redeemApplicationSelectAll();
        PageInfo<RedeemMessage> pageInfo = new PageInfo<>(rule);
        System.out.println("数据："+pageInfo.getPages());
        map.put("code",0);
        map.put("msg","请求成功");
        //count：总数据条数
        map.put("count",pageInfo.getTotal());
        //data：数据
        map.put("data",pageInfo.getList());
        System.out.println(map);
        return map;
    }
}
